package com.edu.exam.entity.exampaper;

import com.edu.exam.entity.core.AuditableEntity;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;

/**
 * 基础试卷实体
 * [所属模块] B-03 试卷管理模块
 * 对应数据库表：basic_exam_papers
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "basic_exam_papers")
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class BasicExamPaper extends AuditableEntity {

    /**
     * 试卷编码
     */
    @Column(name = "paper_code", nullable = false, unique = true, length = 50)
    private String paperCode;

    /**
     * 试卷名称
     */
    @Column(name = "paper_name", nullable = false, length = 200)
    private String paperName;

    /**
     * 试卷描述
     */
    @Column(name = "description", length = 1000)
    private String description;

    /**
     * 考试时长（分钟）
     */
    @Column(name = "duration_minutes")
    private Integer durationMinutes;

    /**
     * 总分
     */
    @Column(name = "total_score", precision = 5, scale = 2)
    private Double totalScore;

    /**
     * 及格分数
     */
    @Column(name = "pass_score", precision = 5, scale = 2)
    private Double passScore;

    /**
     * 题目总数
     */
    @Column(name = "total_questions")
    private Integer totalQuestions;

    /**
     * 试卷类型
     */
    @Column(name = "paper_type", length = 50)
    private String paperType;

    /**
     * 考试形式
     */
    @Column(name = "exam_mode", length = 50)
    private String examMode;

    /**
     * 难度等级
     */
    @Column(name = "difficulty_level", length = 20)
    private String difficultyLevel;

    /**
     * 适用课程编码
     */
    @Column(name = "course_code", length = 50)
    private String courseCode;

    /**
     * 适用考试编码
     */
    @Column(name = "exam_code", length = 50)
    private String examCode;

    /**
     * 考试日期
     */
    @Column(name = "exam_date")
    private java.time.LocalDate examDate;

    /**
     * 是否随机出题
     */
    @Column(name = "is_random")
    private Boolean isRandom;

    /**
     * 是否允许重考
     */
    @Column(name = "allow_retake")
    private Boolean allowRetake;

    /**
     * 最大考试次数
     */
    @Column(name = "max_attempts")
    private Integer maxAttempts;

    /**
     * 试卷文件路径
     */
    @Column(name = "file_path", length = 500)
    private String filePath;

    /**
     * 试卷模板路径
     */
    @Column(name = "template_path", length = 500)
    private String templatePath;

    /**
     * 答案文件路径
     */
    @Column(name = "answer_path", length = 500)
    private String answerPath;

    /**
     * 是否启用防作弊功能
     */
    @Column(name = "anti_cheat_enabled")
    private Boolean antiCheatEnabled;

    /**
     * 是否自动评分
     */
    @Column(name = "auto_grading")
    private Boolean autoGrading;

    /**
     * 试卷状态：草稿、已发布、已归档
     */
    @Column(name = "paper_status", length = 20)
    private String paperStatus;

    /**
     * 创建者编码
     */
    @Column(name = "creator_code", length = 50)
    private String creatorCode;

    /**
     * 审核者编码
     */
    @Column(name = "reviewer_code", length = 50)
    private String reviewerCode;

    /**
     * 审核时间
     */
    @Column(name = "review_time")
    private java.time.LocalDateTime reviewTime;

    /**
     * 审核意见
     */
    @Column(name = "review_comment", length = 1000)
    private String reviewComment;

    /**
     * 试卷版本
     */
    @Column(name = "paper_version", length = 20)
    private String paperVersion;

    /**
     * 是否为标准试卷
     */
    @Column(name = "is_standard")
    private Boolean isStandard;

    /**
     * 标签
     */
    @Column(name = "tags", length = 200)
    private String tags;

    /**
     * 判断试卷是否已发布
     *
     * @return 是否已发布
     */
    public boolean isPublished() {
        return "PUBLISHED".equals(paperStatus);
    }

    /**
     * 判断试卷是否为草稿状态
     *
     * @return 是否为草稿状态
     */
    public boolean isDraft() {
        return "DRAFT".equals(paperStatus);
    }

    /**
     * 判断试卷是否已归档
     *
     * @return 是否已归档
     */
    public boolean isArchived() {
        return "ARCHIVED".equals(paperStatus);
    }

}
